<template>
    <div>
        <table class="table">
            <tbody class="table">
                <tr>
                    <td>房号编号</td>
                    <td>
                        <input type="text" v-model="data.houseNum" disabled>
                    </td>
                </tr>
                <tr>
                    <td>名称</td>
                    <td>
                        <input type="text" v-model="data.houseName">
                    </td>
                </tr>
                <tr>
                    <td>地址</td>
                    <td>
                        <input type="text" v-model="data.address">
                    </td>
                </tr>
                <tr>
                    <td>
                        <input type="file" @change="s">
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td colspan="2">
                        <input type="button" value="添加" @click="add">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref,onMounted } from 'vue';
import { useRouter } from 'vue-router';
onMounted(() => {
  show();  
})

const s=(a:any)=>{
    debugger
    var dd=a.target.files[0];
    console.log(dd);
}

const data=ref({
    "hid": 0,
  "houseNum": "",
  "houseName": "",
  "address": ""
})
const show=()=>{
    var s="2025"
    var d=Math.random().toString().substring(2,6)
    data.value.houseNum=s+d;
}

const router=useRouter();
const add=()=>{
    axios.post("https://localhost:7233/api/House/AddHouse",data.value).then(res=>{
        if(res.data>0){
            alert("添加成功");
            router.push({
                path:'/ShowView'
            })
        }else{
            alert("添加失败")
        }
    })
}


</script>

<style scoped>

</style>